package com.iknow.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class IKnowDatabaseHelper extends SQLiteOpenHelper
{
  public static String DB_NAME = "IKnowData.db";
  public static int DB_VERSION = 5;
  private static Map<Context, IKnowDatabaseHelper> dbmap;

  public IKnowDatabaseHelper(Context paramContext)
  {
    super(paramContext, DB_NAME, null, DB_VERSION);
  }

  public static SQLiteDatabase getDatabase(Context paramContext)
  {
    if (dbmap == null)
      dbmap = Collections.synchronizedMap(new HashMap());
    IKnowDatabaseHelper localIKnowDatabaseHelper = (IKnowDatabaseHelper)dbmap.get(paramContext);
    if (localIKnowDatabaseHelper == null)
    {
      localIKnowDatabaseHelper = new IKnowDatabaseHelper(paramContext);
      dbmap.put(paramContext, localIKnowDatabaseHelper);
    }
    return localIKnowDatabaseHelper.getWritableDatabase();
  }

  public void onCreate(SQLiteDatabase paramSQLiteDatabase)
  {
    paramSQLiteDatabase.execSQL("create table iKnowUser (uid text primary key on conflict replace, password text not null, nick text, email text not null, register text, description text, signature text, image_id text,gender text,user_type text)");
    paramSQLiteDatabase.execSQL("create table qingbo (id text not null, date integer, title text not null, subject text, hot integer, favorite_count integer, comment_count integer, type text not null,thumbnail_url text,jid text not null,user_name text,user_image text,tag text not null,page_type text not null,PRIMARY KEY (id,page_type))");
    paramSQLiteDatabase.execSQL("create table subscribe_tag (user_id text not null,tag_name text not null, system_flag text)");
    paramSQLiteDatabase.execSQL("create table subscribe_qingbo (id text not null, date integer, title text not null, subject text, hot integer, favorite_count integer, comment_count integer, type text not null,thumbnail_url text,jid text not null,user_name text,tag text not null,page_type text not null,subscribe_flag integer)");
    paramSQLiteDatabase.execSQL("create table roster (jid text primary key on conflict replace, name text, avatar text, qingbo_count text, roster_count text, sex text, career text, flag text,description text,signature text,favorite_count text,word_count text,longitude text,latitude text,distance text,subscribe_tag text,subscribe_mode integer)");
    paramSQLiteDatabase.execSQL("create table favorite (id text primary key on conflict replace, date integer, subject text, title text not null, hot integer, favorite_count integer, comment_count integer, type text not null, tag text, thumbnail_url text, jid text not null, user_name text, page_type text not null)");
    paramSQLiteDatabase.execSQL("create table T_BD_STRANGEWORD (key text primary key on conflict replace, user_id text,type text, audioUrl text, pron text, def text, description text, familiarity text, memo text, lang text, date text)");
    paramSQLiteDatabase.execSQL("create table XmppMessage (thread text not null, type text not null, iknowType integer, body text not null, subject text, msgto text not null, msgfrom text not null, msgtime text not null,loc_time text not null,isRead integer,status integer,source text)");
    paramSQLiteDatabase.execSQL("create table session (roster_id text not null, user_id text not null, subject text, date integer,iknow_type integer,total integer,unread_count integer)");
    paramSQLiteDatabase.execSQL("create table xmpp_roster (jid text primary key on conflict replace, name text, subscribe_mode integer, presence integer)");
    paramSQLiteDatabase.execSQL("create table near_by_friends (jid text primary key on conflict replace, name text, avatar text, qingbo_count text, roster_count text, sex text, career text, flag text,description text,signature text,favorite_count text,word_count text,longitude text,latitude text,distance text,subscribe_tag text,subscribe_mode integer)");
  }

  public void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1, int paramInt2)
  {
    paramSQLiteDatabase.execSQL("ALTER TABLE xmpp_roster ADD presence");
  }
}